/**
 * @file     convertToTitle.ts
 * @brief    [168. Excel表列名称](https://leetcode.cn/problems/excel-sheet-column-title/)
 * @author   Zhu
 * @date     2022-10-23 18:27
 */

function convertToTitle(columnNumber: number): string {
    let res = '';

    do {
        columnNumber = columnNumber - 1;
        res = getChar(columnNumber % 26) + res;
        columnNumber = Math.floor(columnNumber / 26);
    } while (columnNumber);

    return res;
}

/* start from 0 */
function getChar(index: number) {
    const start = 'A'.charCodeAt(0);
    return String.fromCodePoint(start + (index % 26));
}
